package cn.jlonely.xyhx.admin.service.impl;

import cn.jlonely.xyhx.admin.mapper.UserMapper;
import cn.jlonely.xyhx.pojo.User;
import cn.jlonely.xyhx.admin.service.UserService;
import cn.jlonely.xyhx.utils.PageResult;
import cn.jlonely.xyhx.utils.SHA256Util;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public PageResult<User> pageUser(Integer page, Integer pageSize, String name) {
        PageHelper.startPage(page, pageSize);

        List<User> users = userMapper.getUserAll(name);

        Page<User> p = (Page<User>) users;

        return new PageResult<>(p.getTotal(), p.getResult());
    }

    @Override
    public void updateUserStatus(Integer id, Integer userStatus) {
        userMapper.updateUserStatus(id, userStatus);
    }

    @Override
    public void resetUserPassword(Integer id) throws Exception {
      String password ="123456";
      String resetPassword= SHA256Util.sha256(password);
      userMapper.resetUserPassword(id,resetPassword);

    }

}
